<?php
use Monolog\Logger;
use Monolog\Handler\StreamHandler;
class mylog{
    public $file;
    public $log;
    public $type;
    public function __construct($name, $type="INFO"){
         $this->file=ROOT_PATH .'/log/default.log';
         $this->log=  new Logger($name);
        $this->type=$type;
        switch($this->type){
            case 'DEBUG':
                $logger=Logger::DEBUG;
                break;
            case 'WARNING':
                $logger=Logger::WARNING;
                break;
            case 'NOTICE':
                $logger=Logger::NOTICE;
                break;
            case 'ERROR':
                $logger=Logger::ERROR;
                break;
            case 'CRITICAL':
                $logger=Logger::CRITICAL;
                break;
            default:
                $logger=Logger::INFO;
                break;
        }
         $this->log->pushHandler(new StreamHandler( $this->file, $logger));
    }

    public function record($str,$file=""){
        if($file!=""){
            $this->file=ROOT_PATH . '/log/'.$file;
        }
        if(is_array($str)){
            $str=var_export($str,true);
        }


        $func = 'add'.ucfirst(strtolower($this->type));
        $this->log->{$func}($str);

    }

}
